home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / archiver / arc.zoo / arc.c next >
C/C++ Source or Header  |  1989-01-29  |  12KB  |  440 lines

  1. /*
  2.  * $Header: arc.c,v 1.13 88/11/01 02:22:23 hyc Exp $
  3.  */
  4.  
  5. /*  ARC - Archive utility
  6.   
  7.     Version 5.21, created on 04/22/87 at 15:05:21
  8.   
  9. (C) COPYRIGHT 1985-87 by System Enhancement Associates; ALL RIGHTS RESERVED
  10.   
  11.     By:     Thom Henderson
  12.   
  13.     Description:
  14.      This program is a general archive utility, and is used to maintain
  15.      an archive of files.  An "archive" is a single file that combines
  16.      many files, reducing storage space and allowing multiple files to
  17.      be handled as one.
  18.   
  19.     Instructions:
  20.      Run this program with no arguments for complete instructions.
  21.   
  22.     Programming notes:
  23.      ARC Version 2 differs from version 1 in that archive entries
  24.      are automatically compressed when they are added to the archive,
  25.      making a separate compression step unecessary.     The nature of the
  26.      compression is indicated by the header version number placed in
  27.      each archive entry, as follows:
  28.   
  29.      1 = Old style, no compression
  30.      2 = New style, no compression
  31.      3 = Compression of repeated characters only
  32.      4 = Compression of repeated characters plus Huffman SQueezing
  33.      5 = Lempel-Zev packing of repeated strings (old style)
  34.      6 = Lempel-Zev packing of repeated strings (new style)
  35.      7 = Lempel-Zev Williams packing with improved hash function
  36.      8 = Dynamic Lempel-Zev packing with adaptive reset
  37.      9 = Dynamic Lempel-Zev packing, larger hash table
  38.   
  39.      Type 5, Lempel-Zev packing, was added as of version 4.0
  40.   
  41.      Type 6 is Lempel-Zev packing where runs of repeated characters
  42.      have been collapsed, and was added as of version 4.1
  43.   
  44.      Type 7 is a variation of Lempel-Zev using a different hash
  45.      function which yields speed improvements of 20-25%, and was
  46.      added as of version 4.6
  47.   
  48.      Type 8 is a different implementation of Lempel-Zev, using a
  49.      variable code size and an adaptive block reset, and was added
  50.      as of version 5.0
  51.   
  52.      Type 9 is a slight modification of type 8, first used by Phil
  53.      Katz in his PKARC utilites. The primary difference is the use
  54.      of a hash table twice as large as for type 8, and that this
  55.      algorithm called Squashing, doesn't perform run-length encoding
  56.      on the input data.
  57.   
  58.      Verion 4.3 introduced a temporary file for holding the result
  59.      of the first crunch pass, thus speeding up crunching.
  60.   
  61.      Version 4.4 introduced the ARCTEMP environment string, so that
  62.      the temporary crunch file may be placed on a ramdisk.    Also
  63.      added was the distinction bewteen Adding a file in all cases,
  64.      and Updating a file only if the disk file is newer than the
  65.      corresponding archive entry.
  66.   
  67.      The compression method to use is determined when the file is
  68.      added, based on whichever method yields the smallest result.
  69.   
  70.     Language:
  71.      Computer Innovations Optimizing C86
  72. */
  73. #include <stdio.h>
  74. #include "arc.h"
  75.  
  76. #if    UNIX
  77. #include <sys/types.h>
  78. #include <sys/stat.h>
  79. #endif
  80.  
  81. #ifndef __STDC__
  82. int        strlen();
  83. #endif
  84. void        addarc(), delarc(), extarc(), lstarc(), tstarc(), cvtarc(), runarc();
  85. void        abort();
  86. static    void    expandlst();
  87. #if    MTS
  88. void        etoa();
  89. #endif
  90. #if    GEMDOS
  91. long        _stksize = 65536L;
  92. #endif
  93. #ifndef __STDC__
  94. char        *strcpy(), *strcat();
  95. #endif
  96. char        *makefnam();    /* filename fixup routine */
  97.  
  98. static char   **lst;        /* files list */
  99. static int    lnum;        /* length of files list */
  100.  
  101. main(num, arg)            /* system entry point */
  102.     int        num;    /* number of arguments */
  103.     char           *arg[];    /* pointers to arguments */
  104. {
  105.     char        opt = 0;/* selected action */
  106.     char           *a;    /* option pointer */
  107.     void        upper();/* case conversion routine */
  108. #ifndef __STDC__
  109.     char           *index();/* string index utility */
  110. #endif
  111.     char           *envfind();    /* environment searcher */
  112.     int        n;    /* index */
  113.     char           *arctemp2;
  114. #ifndef __STDC__
  115.     char        *calloc(), *mktemp();
  116. #endif
  117. #if    GEMDOS
  118.     void        exitpause();
  119.     int        append;
  120. #endif
  121. #if    MTS
  122.     fortran void    guinfo();
  123.     char        gotinf[4];
  124. #endif
  125. #if    UNIX
  126.     struct    stat    sbuf;
  127. #endif
  128.  
  129.     if (num < 3) {
  130.         printf("ARC - Archive utility, Version 5.21, created on 04/22/87 at 15:05:21\n");
  131. /*        printf("(C) COPYRIGHT 1985,86,87 by System Enhancement Associates;");
  132.         printf(" ALL RIGHTS RESERVED\n\n");
  133.         printf("Please refer all inquiries to:\n\n");
  134.         printf("       System Enhancement Associates\n");
  135.         printf("       21 New Street, Wayne NJ 07470\n\n");
  136.         printf("You may copy and distribute this program freely,");
  137.         printf(" provided that:\n");
  138.         printf("    1)     No fee is charged for such copying and");
  139.         printf(" distribution, and\n");
  140.         printf("    2)     It is distributed ONLY in its original,");
  141.         printf(" unmodified state.\n\n");
  142.         printf("If you like this program, and find it of use, then your");
  143.         printf(" contribution will\n");
  144.         printf("be appreciated.     You may not use this product in a");
  145.         printf(" commercial environment\n");
  146.         printf("or a governmental organization without paying a license");
  147.         printf(" fee of $35.  Site\n");
  148.         printf("licenses and commercial distribution licenses are");
  149.         printf(" available.  A program\n");
  150.         printf("disk and printed documentation are available for $50.\n");
  151.         printf("\nIf you fail to abide by the terms of this license, ");
  152.         printf(" then your conscience\n");
  153.         printf("will haunt you for the rest of your life.\n\n"); */
  154. #if    MSDOS
  155.         printf("Usage: ARC {amufdxerplvtc}[bswnoq][g<password>]");
  156. #endif
  157. #if    GEMDOS
  158.         printf("Usage: ARC {amufdxerplvtc}[bhswnoq][g<password>]");
  159. #endif
  160. #if    UNIX
  161.         printf("Usage: arc {amufdxerplvtc}[biswnoq][g<password>]");
  162. #endif
  163. #if    MTS
  164.         printf("Parameters: {amufdxeplvtc}[biswnoq][g<password>]");
  165. #endif
  166.         printf(" <archive> [<filename> . . .]\n");
  167.         printf("Where:     a   = add files to archive\n");
  168.         printf("     m   = move files to archive\n");
  169.         printf("     u   = update files in archive\n");
  170.         printf("     f   = freshen files in archive\n");
  171.         printf("     d   = delete files from archive\n");
  172.         printf("     x,e = extract files from archive\n");
  173. #if    !MTS
  174.         printf("     r   = run files from archive\n");
  175. #endif
  176.         printf("     p   = copy files from archive to");
  177.         printf(" standard output\n");
  178.         printf("     l   = list files in archive\n");
  179.         printf("     v   = verbose listing of files in archive\n");
  180.         printf("     t   = test archive integrity\n");
  181.         printf("     c   = convert entry to new packing method\n");
  182.         printf("     b   = retain backup copy of archive\n");
  183. #if    GEMDOS
  184.         printf("     h   = hold screen after finishing\n");
  185. #endif
  186. #if    MTS
  187.         printf("     i   = suppress ASCII/EBCDIC translation\n");
  188. #endif
  189. #if    UNIX
  190.         printf("     i   = suppress image mode (translate EOL)\n");
  191. #endif
  192.         printf("     s   = suppress compression (store only)\n");
  193.         printf("     w   = suppress warning messages\n");
  194.         printf("     n   = suppress notes and comments\n");
  195.         printf("     o   = overwrite existing files when");
  196.         printf(" extracting\n");
  197.         printf("     q   = squash instead of crunching\n");
  198.         printf("     g   = Encrypt/decrypt archive entry\n");
  199.         printf("\nAdapted from MSDOS by Howard Chu\n");
  200.         /*
  201.          * printf("\nPlease refer to the program documentation for");
  202.          * printf(" complete instructions.\n"); 
  203.          */
  204. #if    GEMDOS
  205.         exitpause();
  206. #endif
  207.         return 1;
  208.     }
  209.     /* see where temp files go */
  210. #if    !MTS
  211.     arctemp = calloc(1, STRLEN);
  212.     if (!(arctemp2 = envfind("ARCTEMP")))
  213.         arctemp2 = envfind("TMPDIR");
  214.     if (arctemp2) {
  215.         strcpy(arctemp, arctemp2);
  216.         n = strlen(arctemp);
  217.         if (arctemp[n - 1] != CUTOFF)
  218.             arctemp[n] = CUTOFF;
  219.     }
  220. #if    UNIX
  221.     else    strcpy(arctemp, "/tmp/");
  222. #endif
  223. #if    !MSDOS
  224.     {
  225.         static char tempname[] = "AXXXXXX";
  226.         strcat(arctemp, mktemp(tempname));
  227.     }
  228. #else
  229.     strcat(arctemp, "$ARCTEMP");
  230.     arctemp2 = NULL;
  231. #endif
  232. #else
  233.     guinfo("SHFSEP    ", gotinf);
  234.     sepchr[0] = gotinf[0];
  235.     guinfo("SCRFCHAR", gotinf);
  236.     tmpchr[0] = gotinf[0];
  237.     arctemp = "-$$$";
  238.     arctemp[0] = tmpchr[0];
  239. #endif
  240.  
  241. #if    !UNIX
  242.     /* avoid any case problems with arguments */
  243.  
  244.     for (n = 1; n < num; n++)    /* for each argument */
  245.         upper(arg[n]);    /* convert it to uppercase */
  246. #else
  247.     /* avoid case problems with command options */
  248.     upper(arg[1]);        /* convert to uppercase */
  249. #endif
  250.  
  251.     /* create archive names, supplying defaults */
  252. #if    UNIX
  253.     if (!stat(arg[2],&sbuf)) {
  254.         if ((sbuf.st_mode & S_IFMT) == S_IFDIR)
  255.             makefnam(arg[2],".arc",arcname);
  256.         else
  257.             strcpy(arcname,arg[2]);
  258.     } else
  259.         makefnam(arg[2],".arc",arcname);
  260. #else
  261.     makefnam(arg[2], ".ARC", arcname);
  262. #endif
  263.     /* makefnam(".$$$",arcname,newname); */
  264.